package com.kaixin001.tk;

import java.util.HashMap;

import com.kaixin001.tk.api.ContextContainer;
import com.kaixin001.tk.exceptions.ContextNotFoundException;

public class ContextContainerImpl implements ContextContainer {
	
	private HashMap<String,Object> objects = new HashMap<String,Object>();

	ContextContainerImpl()
	{
		
	}
	
	public Object get(String name) throws ContextNotFoundException {
		
		Object obj = objects.get(name);
		if(obj==null)
		{
			throw new ContextNotFoundException("ConextContainer do not contain Object for key name:"+name);
		}
		
		return obj;
	}

	public boolean isContain(String name) {
		return objects.containsKey(name);
	}

	public Object put(String name, Object obj) {
		
		Object oldObject = null;
		if(objects.containsKey(name))
		{
			oldObject= objects.get(name);
	
		}
		objects.put(name, obj);		
		return oldObject;
			
	}

}
